package view;

import lib.gui.ScreenTemplate;
import net.rim.blackberry.api.bbm.platform.BBMPlatformApplication;
import net.rim.blackberry.api.bbm.platform.BBMPlatformContextListener;
import net.rim.blackberry.api.bbm.platform.BBMPlatformManager;
import net.rim.device.api.ui.UiApplication;

public class Start extends UiApplication {
	public static MyBBMAppPlugin BBMInfo;
	/**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        Start theApp = new Start();       
        theApp.enterEventDispatcher();
    }
    
    /**
     * Creates a new MapYork object
     */
    public Start()
    {
    	try{
    		BBMInfo = new MyBBMAppPlugin();
    	}catch(Exception e)
    	{
    		System.out.println("ERROR::"+e.getMessage()+" :: "+ e.toString());
    	}
    	// Push a screen onto the UI stack for rendering.
        //pushScreen(new Mingle());
    	pushScreen(new SplashScreen());
        invokeLater(new Runnable()
        {
          public void run()
            {
        	  try 
              {
        		  ScreenTemplate.platformContext = 
        			  BBMPlatformManager.register(BBMInfo);
              }catch(Exception e)
              {
            	  System.out.println(e.getMessage());
              }
              if (ScreenTemplate.platformContext != null) 
              {
	              MyBBMPlatformContextListener platformContextListener;
	              platformContextListener = new MyBBMPlatformContextListener();
	              ScreenTemplate.platformContext.setListener(platformContextListener);
              }
            }
        }	
      );
    }
    
    private class MyBBMPlatformContextListener extends BBMPlatformContextListener
    {
        public void accessChanged(boolean isAccessAllowed, int accessErrorCode)
        {
            if (!isAccessAllowed)
            {
                // You cannot access the BBM platform
            }
        }

        public void appInvoked(int reason, Object param)
        {
            // Code for handling different contexts for invocation
        }
    }
    
    private class MyBBMAppPlugin extends BBMPlatformApplication
    {
        public MyBBMAppPlugin()
        {
            super( "BLACKBERRYMINGLEBYVOIDDIGITSMAY2012$" );
        }
    }
    
}
